package com.aspose.cells;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class HyperlinkCollection extends CollectionBase {
   private Object b;

   HyperlinkCollection(Object parent) {
      this.b = parent;
   }

   Worksheet a() {
      return this.b instanceof Worksheet ? (Worksheet)this.b : null;
   }

   public int add(int firstRow, int firstColumn, int totalRows, int totalColumns, String address) {
      if (this.getCount() >= 65530) {
         throw new CellsException(10, "The count of Hyperlinks cannot be larger than 66530.");
      } else {
         zakq.a(firstRow, firstColumn, firstRow + totalRows - 1, firstColumn + totalColumns - 1);
         String var6 = address.toLowerCase();
         CellArea var7 = new CellArea();
         var7.StartRow = firstRow;
         var7.StartColumn = firstColumn;
         var7.EndRow = firstRow + totalRows - 1;
         var7.EndColumn = firstColumn + totalColumns - 1;
         Hyperlink var8 = new Hyperlink(this, var7);
         var8.a(address);
         if (!var6.startsWith("http:") && !var6.startsWith("www.") && !var6.startsWith("https:") && !var6.startsWith("mailto:")) {
            var8.b(true);
            if (address.length() > 2 && address.charAt(1) == ':') {
               var8.a(true);
            }
         }

         if (var6.startsWith("www.")) {
            var8.setAddress("http://" + address);
         } else {
            var8.setAddress(address);
         }

         com.aspose.cells.b.a.a.ze.a(this.a, (Object)var8);
         return this.getCount() - 1;
      }
   }

   private int b(int var1, int var2, int var3, int var4, String var5) {
      zakq.a(var1, var2, var1 + var3 - 1, var2 + var4 - 1);
      CellArea var6 = new CellArea();
      var6.StartRow = var1;
      var6.StartColumn = var2;
      var6.EndRow = var1 + var3 - 1;
      var6.EndColumn = var2 + var4 - 1;
      Hyperlink var7 = new Hyperlink(this, var6);
      var7.setAddress(var5);
      var7.b(var5);
      var7.b(true);
      if (var5.length() > 2 && var5.charAt(1) == ':') {
         var7.a(true);
      }

      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var7);
      return this.a.size() - 1;
   }

   int a(int var1, int var2, int var3, int var4, String var5) {
      zakq.a(var1, var2, var1 + var3 - 1, var2 + var4 - 1);
      if (var5 != null) {
         String var6 = var5.toLowerCase();
         if (!var6.startsWith("http:") && !var6.startsWith("www.") && !var6.startsWith("https:") && !var6.startsWith("mailto:")) {
            return this.b(var1, var2, var3, var4, var5);
         }
      }

      CellArea var8 = new CellArea();
      var8.StartRow = var1;
      var8.StartColumn = var2;
      var8.EndRow = var1 + var3 - 1;
      var8.EndColumn = var2 + var4 - 1;
      Hyperlink var7 = new Hyperlink(this, var8);
      var7.setAddress(var5);
      var7.b(var5);
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var7);
      return this.a.size() - 1;
   }

   public int add(String cellName, int totalRows, int totalColumns, String address) {
      byte var5 = 0;
      byte var6 = 0;
      int[] var7 = new int[]{var5};
      int[] var8 = new int[]{var6};
      CellsHelper.a(cellName, var7, var8);
      int var9 = var7[0];
      int var10 = var8[0];
      return this.add(var9, var10, totalRows, totalColumns, address);
   }

   public int add(String startCellName, String endCellName, String address, String textToDisplay, String screenTip) {
      byte var6 = 0;
      byte var7 = 0;
      int[] var8 = new int[]{var6};
      int[] var9 = new int[]{var7};
      CellsHelper.a(startCellName, var8, var9);
      int var16 = var8[0];
      int var17 = var9[0];
      byte var10 = 0;
      byte var11 = 0;
      int[] var12 = new int[]{var10};
      int[] var13 = new int[]{var11};
      CellsHelper.a(endCellName, var12, var13);
      int var18 = var12[0];
      int var19 = var13[0];
      int var14 = this.add(var16, var17, var18 - var16 + 1, var19 - var17 + 1, address);
      Hyperlink var15 = this.get(var14);
      if (textToDisplay != null && !"".equals(textToDisplay)) {
         var15.setTextToDisplay(textToDisplay);
      }

      if (screenTip != null && !"".equals(screenTip)) {
         var15.setScreenTip(screenTip);
      }

      return var14;
   }

   int a(Hyperlink var1) {
      com.aspose.cells.b.a.a.ze.a(this.a, (Object)var1);
      return this.a.size() - 1;
   }

   public Hyperlink get(int index) {
      return (Hyperlink)this.a.get(index);
   }

   void a(int var1) {
      this.a.remove(var1);
   }

   public void removeAt(int index) {
      Hyperlink var2 = (Hyperlink)this.a.get(index);
      this.a.remove(index);
      Worksheet var3 = this.a();
      if (var3 != null) {
         CellArea var4 = var2.getArea();
         RowCollection var5 = var3.getCells().getRows();

         for(int var6 = var4.StartRow; var6 <= var4.EndRow; ++var6) {
            Row var7 = var5.a(var6, true, false, false);
            if (var7 != null) {
               for(int var8 = var4.StartColumn; var8 <= var4.EndColumn; ++var8) {
                  Cell var9 = var7.getCellOrNull(var8);
                  if (var9 != null) {
                     var9.a((Style)null);
                  }
               }
            }
         }

      }
   }

   public void clear() {
      for(int var1 = 0; var1 < this.getCount(); ++var1) {
         Hyperlink var2 = (Hyperlink)this.a.get(var1);
         Worksheet var3 = this.a();
         if (var3 == null) {
            return;
         }

         CellArea var4 = var2.getArea();
         RowCollection var5 = var3.getCells().getRows();

         for(int var6 = var4.StartRow; var6 <= var4.EndRow; ++var6) {
            Row var7 = var5.a(var6, true, false, false);
            if (var7 != null) {
               for(int var8 = var4.StartColumn; var8 <= var4.EndColumn; ++var8) {
                  Cell var9 = var7.getCellOrNull(var8);
                  if (var9 != null) {
                     var9.b(15);
                  }
               }
            }
         }
      }

      this.a.clear();
   }

   void a(HyperlinkCollection var1) {
      this.a.clear();

      for(int var2 = 0; var2 < var1.a.size(); ++var2) {
         Hyperlink var3 = (Hyperlink)var1.a.get(var2);
         Hyperlink var4 = new Hyperlink();
         var4.a(var3);
         com.aspose.cells.b.a.a.ze.a(this.a, (Object)var4);
      }

   }

   void a(int var1, int var2) {
      for(int var3 = 0; var3 < this.a.size(); ++var3) {
         Hyperlink var4 = this.get(var3);
         CellArea var5 = var4.getArea();
         boolean var6 = false;
         boolean[] var7 = new boolean[]{var6};
         var5 = zayd.a(var5, var1, var2, var7);
         var6 = var7[0];
         if (var6) {
            this.a(var3--);
         } else {
            var4.a(var5);
         }
      }

   }

   void b(int var1, int var2) {
      for(int var3 = 0; var3 < this.a.size(); ++var3) {
         Hyperlink var4 = this.get(var3);
         CellArea var5 = var4.getArea();
         boolean var6 = false;
         boolean[] var7 = new boolean[]{var6};
         var5 = zayd.b(var5, var1, var2, var7);
         var6 = var7[0];
         if (var6) {
            this.a(var3--);
         } else {
            var4.a(var5);
         }
      }

   }

   void a(CellArea var1, int var2, int var3) {
      switch(var3) {
      case 0:
         this.b(var1, var2);
      case 1:
      case 2:
      default:
         break;
      case 3:
         this.c(var1, var2);
         break;
      case 4:
         this.a(var1, var2);
      }

   }

   private void a(CellArea var1, int var2) {
      int var3 = this.a.size();
      boolean var4 = this.a().c().n().j();
      ArrayList var5 = new ArrayList();
      ArrayList var6 = new ArrayList();

      for(int var7 = 0; var7 < var3; ++var7) {
         var5.clear();
         var6.clear();
         Hyperlink var8 = this.get(var7);
         CellArea var9 = var8.getArea();
         zayd.c(var4, var1, var2, var9, var5, var6);
         com.aspose.cells.b.a.a.ze.a(var5, (Collection)var6);
         if (var5.size() > 0) {
            var8.a((CellArea)var5.get(0));
         }

         for(int var10 = 1; var10 < var5.size(); ++var10) {
            Hyperlink var11 = new Hyperlink();
            var11.a(var8);
            var11.a((CellArea)var5.get(var10));
            com.aspose.cells.b.a.a.ze.a(this.a, (Object)var11);
         }
      }

   }

   private void b(CellArea var1, int var2) {
      for(int var3 = 0; var3 < this.a.size(); ++var3) {
         Hyperlink var4 = this.get(var3);
         CellArea var5 = var4.getArea();
         if (var1.StartColumn <= var5.StartColumn && var1.EndColumn >= var5.EndColumn) {
            if (var1.StartRow <= var5.StartRow) {
               var5.StartRow += var2;
               var5.EndRow += var2;
            } else if (var1.StartRow <= var5.EndRow) {
               var5.EndRow += var2;
            }

            var4.a(var5);
         }
      }

   }

   private void c(CellArea var1, int var2) {
      for(int var3 = 0; var3 < this.a.size(); ++var3) {
         Hyperlink var4 = this.get(var3);
         CellArea var5 = var4.getArea();
         if (var1.StartRow <= var5.StartRow && var1.EndRow >= var5.EndRow) {
            if (var1.StartColumn <= var5.StartColumn) {
               var5.StartColumn += var2;
               var5.EndColumn += var2;
            } else if (var1.StartColumn <= var5.EndColumn) {
               var5.EndColumn += var2;
            }
         }
      }

   }

   void a(HyperlinkCollection var1, int var2, int var3, int var4) {
      CellArea var5 = CellArea.createCellArea(0, var2, 1048575, var2 + var4 - 1);
      CellArea var6 = CellArea.createCellArea(0, var3, 1048575, var3 + var4 - 1);
      this.a(var1, var5, var6);
   }

   void b(HyperlinkCollection var1, int var2, int var3, int var4) {
      CellArea var5 = CellArea.createCellArea(var2, 0, var2 + var4 - 1, 16383);
      CellArea var6 = CellArea.createCellArea(var3, 0, var3 + var4 - 1, 16383);
      this.a(var1, var5, var6);
   }

   void a(HyperlinkCollection var1, CellArea var2, CellArea var3) {
      if (this.getCount() < 65530) {
         boolean var4 = var1.a() == this.a();
         int var5 = this.getCount();
         int var6;
         Hyperlink var7;
         Object var8;
         ArrayList var9;
         Iterator var10;
         CellArea var11;
         Hyperlink var12;
         if (!var4) {
            for(var6 = 0; var6 < var5; ++var6) {
               var7 = this.get(var6);
               var8 = zayd.e(var7.getArea(), var3);
               if (var8 != null) {
                  var9 = zayd.d(var7.b, (CellArea)var8);
                  if (var9.size() != 0) {
                     var10 = var9.iterator();

                     while(var10.hasNext()) {
                        var11 = (CellArea)var10.next();
                        var12 = new Hyperlink(this, var11);
                        var12.b(var7);
                        this.a(var12);
                     }
                  }

                  this.a(var6);
                  --var6;
                  --var5;
               }
            }
         }

         var5 = var1.getCount();

         for(var6 = 0; var6 < var5; ++var6) {
            var7 = var1.get(var6);
            var8 = null;
            if (var4) {
               var8 = zayd.e(var7.getArea(), var3);
               if (var8 != null) {
                  var9 = zayd.d(var7.b, (CellArea)var8);
                  if (var9.size() != 0) {
                     var10 = var9.iterator();

                     while(var10.hasNext()) {
                        var11 = (CellArea)var10.next();
                        var12 = new Hyperlink(this, var11);
                        var12.b(var7);
                        this.a(var12);
                     }
                  }

                  this.a(var6);
                  --var6;
                  --var5;
               }
            }

            var8 = zayd.e(var7.getArea(), var2);
            if (var8 != null) {
               CellArea var18 = (CellArea)var8;
               int var19 = var18.StartRow - var2.StartRow;
               int var20 = var18.StartColumn - var2.StartColumn;
               int var21 = var3.StartRow + var19;
               int var13 = var3.StartColumn + var20;
               CellArea var14 = new CellArea();
               var14.StartRow = var21;
               var14.StartColumn = var13;
               var14.EndRow = var21 + var18.EndRow - var18.StartRow;
               var14.EndColumn = var13 + var18.EndColumn - var18.StartColumn;
               if (var4) {
                  boolean var15 = true;
                  CellArea var16 = var7.b;
                  boolean[] var17 = new boolean[]{var15};
                  var16 = zayd.a(var16, var14, var17);
                  var15 = var17[0];
                  if (var15) {
                     var7.b = var16;
                     continue;
                  }
               }

               Hyperlink var22 = new Hyperlink(this, var14);
               var22.b(var7);
               if (var4) {
                  this.a(var22);
               } else {
                  this.b(var22);
               }
            }
         }

      }
   }

   private void b(Hyperlink var1) {
      CellArea var2 = var1.b;

      for(int var3 = 0; var3 < this.getCount(); ++var3) {
         Hyperlink var4 = this.get(var3);
         if (var1.c(var4)) {
            boolean var5 = false;
            CellArea var6 = var4.b;
            boolean[] var7 = new boolean[]{var5};
            var6 = zayd.a(var6, var2, var7);
            var5 = var7[0];
            if (var5) {
               var4.b = var6;
               return;
            }
         }
      }

      this.a(var1);
   }

   void a(byte[] var1) {
      int var2 = com.aspose.cells.b.a.zc.e(var1, 0) & '\uffff';
      int var3 = com.aspose.cells.b.a.zc.e(var1, 2) & '\uffff';
      int var4 = var1[4] & 255;
      int var5 = var1[6] & 255;
      if (var5 < var4) {
         int var6 = var5;
         var5 = var4;
         var4 = var6;
      }

      String var16 = null;
      byte var7 = 28;
      byte[] var8 = new byte[4];
      System.arraycopy(var1, var7, var8, 0, 4);
      int var17 = var7 + 4;
      int var9;
      int var10;
      if ((var8[0] & 255 & 16) != 0) {
         var9 = com.aspose.cells.b.a.zc.a(var1, var17);
         var17 += 4;
         var10 = var9 + var9 - 2;
         var16 = Encoding.getUnicode().a(var1, var17, var10);
         var17 += var10 + 2;
      }

      if ((var8[0] & 255 & 128) != 0) {
         var9 = com.aspose.cells.b.a.zc.a(var1, var17);
         var17 += 4 + var9 + var9;
      }

      String var11 = "";
      if ((var8[0] & 255 & 1) != 0) {
         boolean var12 = (var8[1] & 255 & 1) != 0;
         boolean var13 = false;
         if (!var12) {
            if (var1[var17] == 3 && var1[var17 + 1] == 3) {
               int[] var14 = new int[]{var17};
               var11 = this.a(var1, var14);
               var17 = var14[0];
               var13 = true;
            } else {
               var17 += 16;
            }
         }

         int var19;
         if (!var13) {
            var9 = com.aspose.cells.b.a.zc.a(var1, var17);
            var17 += 4;
            var10 = var9 - 2;
            if (var12) {
               var10 += var9;
            }

            if (var10 + var17 > var1.length) {
               var10 = var1.length - var17;
            }

            var11 = Encoding.getUnicode().a(var1, var17, var10);
            var19 = var11.indexOf(0);
            if (var19 != -1) {
               var11 = var11.substring(0, 0 + var19);
            }

            var17 += var10 + 2;
         }

         if ((var8[0] & 255 & 8) != 0) {
            var19 = com.aspose.cells.b.a.zc.a(var1, var17);
            if (4 + var19 * 2 + var17 <= var1.length) {
               var17 += 4;
               String var15 = Encoding.getUnicode().a(var1, var17, (var19 - 1) * 2);
               var11 = var11 + "#" + var15;
            }
         }
      } else if (var17 < var1.length) {
         var9 = com.aspose.cells.b.a.zc.a(var1, var17);
         var17 += 4;
         var10 = var9 + var9 - 2;
         var11 = Encoding.getUnicode().a(var1, var17, var10);
      }

      int var18 = this.a(var2, var4, var3 - var2 + 1, var5 - var4 + 1, var11);
      if (var16 != null && !"".equals(var16)) {
         this.get(var18).b(var16);
      }

   }

   private String a(byte[] var1, int[] var2) {
      var2[0] += 16;
      short var3 = com.aspose.cells.b.a.zc.b(var1, var2[0]);
      var2[0] += 2;
      int var4 = com.aspose.cells.b.a.zc.a(var1, var2[0]);
      var2[0] += 4;
      String var5 = Encoding.getDefault().a(var1, var2[0], var4 - 1);
      if (var3 > 0) {
         StringBuilder var6 = new StringBuilder();

         for(int var7 = 0; var7 < var3; ++var7) {
            var6.append("..\\");
         }

         var5 = com.aspose.cells.b.a.zr.a(var6) + var5;
      }

      var2[0] += var4 + 24;
      int var8 = com.aspose.cells.b.a.zc.a(var1, var2[0]);
      if (var8 != 0) {
         var4 = com.aspose.cells.b.a.zc.a(var1, var2[0] + 4);
         var5 = Encoding.getUnicode().a(var1, var2[0] + 10, var4);
      }

      var2[0] += 4 + var8;
      return var5;
   }
}
